import redis

from chat.settings import POOL


def jwt_response_payload_handler(token, user=None, request=None):
    """单点登入验证,每次登入保存最新的token"""
    k = 'latest_user_{}'.format(user.id)
    value = token
    cache = redis.Redis(connection_pool=POOL)
    cache.set(k, value)
    return {
        'token': token
    }
